# configure-tftpd-hpa.pm
# Copyright (C) 2006, 2007 Stephane Alnet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

#
# For more information: http://carrierclass.net/
#

package CCNv2::Provision::Application::tftpd;
use strict; use warnings;
use CCNCore::Provision::Base;
use base qw(CCNCore::Provision::Base);
use CCN::Text;
use CCNCore::Scripting;

sub run()
{
    my $self = shift;

    $self->PACKAGE ('tftpd-hpa');
    $self->CHECKFOR ('/etc/init.d/tftpd-hpa');
    $self->CHECKFOR ('/usr/sbin/in.tftpd');
    mkdir CCNv2::Home::tftpboot unless -d CCNv2::Home::tftpboot;
    $self->CHECKFOR (CCNv2::Home::tftpboot);

    # Should TFTPd be enabled?
    $self->disable('tftpd-hpa'),
    return
        unless $self->p->is_a_file_server;

    $self->enable('tftpd-hpa');

    my $done = 0;
    # YYYPORT RedHat options



    # Debian options
    if( $self->p->operating_system =~ /^(debian|ccn)/ )
    {
        $done = 1,
        CAT '/etc/default/tftpd-hpa', <<'EOT' if -e '/etc/default/tftpd-hpa';
#Defaults for tftpd-hpa
RUN_DAEMON="yes"
OPTIONS="-l -s -v /home/tftpboot"
EOT
        # On etch, restart does not work cleanly.
        IF_CHANGED '/etc/default/tftpd-hpa' => '/etc/init.d/tftpd-hpa stop; /etc/init.d/tftpd-hpa start';
    }

    $self->error( "Can't find tfptd-hpa configuration, is tftpd-hpa installed?" )
        unless $done;

    # ZZZ Per MAC address boot file for Cisco phones.

}
1;